#include "dshNozzle2dMesh.h"

#include "readFile.h"
#include "mesh.h"
#include "s2dMesh.h"
#include <vector>
#include <cstdio>

using namespace std;

int main(int argc,char** argv){
    vector<fileData> meshPara=readFileData((char *)"./mesh/meshPara");
    mesh::getMeshPara(meshPara);
    nozzle2dMesh::getNozzleGeo(meshPara);
    nozzle2dMesh::getOtherWall();
    s2dMesh::getCurvePoint(nozzle2dMesh::nozzleGeo,s2dMesh::xNum,false);
    s2dMesh::getCurvePoint(nozzle2dMesh::otherWall[0],s2dMesh::yNum,true);
    s2dMesh::getCurvePoint(nozzle2dMesh::otherWall[1],s2dMesh::xNum,true);
    s2dMesh::getCurvePoint(nozzle2dMesh::otherWall[2],s2dMesh::yNum,true);
    s2dMesh::meshInit();
    s2dMesh::writeMesh();
    s2dMeshOpt::optMesh();
    return 0;
}

int nozzle2dMesh::getNozzleGeo(vector<fileData> meshPara)
{
    string fileName;
    for(int k=0;k<meshPara.size();k++){
        if(meshPara[k].type=="nozzleGeo"){
            fileName=meshPara[k].value;
            break;
        }
    }
    cout<<"Reading nozzle geo from "<<fileName<<"."<<endl;
    char *tempStr;
    tempStr=readFileStr((char *)fileName.c_str());
    stringstream tempStream(tempStr);
    int k=0;
    mesh::point2d tempPoint;
    while(tempStream>>tempPoint.x>>tempPoint.y){
        nozzleGeo.push_back(tempPoint);
        k++;
    }
    cout<<"\t"<<k<<" points."<<endl;
    cout<<"Done reading nozzle geo."<<endl<<endl;
    return 0;
}

int nozzle2dMesh::getOtherWall()
{
    vector<mesh::point2d> tempLine1,tempLine2,tempLine3;
    mesh::point2d tempPoint;
    tempPoint.x=nozzleGeo[nozzleGeo.size()-1].x;
    tempPoint.y=nozzleGeo[nozzleGeo.size()-1].y;
    tempLine1.push_back(tempPoint);
    tempPoint.x=nozzleGeo[nozzleGeo.size()-1].x;
    tempPoint.y=0;
    tempLine1.push_back(tempPoint);

    tempLine2.push_back(tempPoint);
    tempPoint.x=nozzleGeo[0].x;
    tempLine2.push_back(tempPoint);

    tempLine3.push_back(tempPoint);
    tempPoint.y=nozzleGeo[0].y;
    tempLine3.push_back(tempPoint);

    otherWall.push_back(tempLine1);
    otherWall.push_back(tempLine2);
    otherWall.push_back(tempLine3);
    return 0;
}

void test()
{
    cout<<"1";
    cout<<mesh::meshType<<"1"<<endl;
    cout<<s2dMesh::xNum<<endl;
}

